package by.amakarevich.services.impl;

import javax.inject.Inject;

import org.apache.commons.lang3.Validate;
import org.springframework.stereotype.Service;

import by.amakarevich.dataaccess.WoolDao;
import by.amakarevich.dataaccess.ProductDao;
import by.amakarevich.datamodel.Wool;
import by.amakarevich.datamodel.Product;
import by.amakarevich.services.WoolService;

@Service
public class WoolServiceImpl implements WoolService {

	@Inject
	private WoolDao woolDao;
	
	@Inject
	private ProductDao productDao;
	
	@Override
	public void createNewWool(Wool wool,  Product product) {
		Validate.isTrue(wool.getId() == null, "This method should be called for 'not saved yet' profile only. Use UPDATE instead");
		wool.setProduct(product);
		woolDao.insert(wool);
	}

	@Override
	public Wool get(Long id) {
		return woolDao.getById(id);
	}

	@Override
	public void updateWool(Wool wool) {
		woolDao.update(wool);
	}

	@Override
	public void removeWool(Long id) {

		woolDao.delete(id);
		productDao.delete(id);

	}
	  @Override
	    public void deleteAll() {
		  woolDao.deleteAll();
		  productDao.deleteAll();
	    }
}
